<template>
  <el-form ref="form" :model="userInfo" label-width="120px" style="text-align: left;">
    <el-form-item label="用户名">
      <el-input v-model="userInfo.username" readonly></el-input>
    </el-form-item>
    <el-form-item label="登录密码">
      <el-input v-model="userInfo.password"></el-input>
    </el-form-item>
    <el-form-item label="私钥">
      <el-input v-model="userInfo.secretKey"></el-input>
    </el-form-item>
    <el-form-item label="公钥">
      <el-input v-model="userInfo.publicKey"></el-input>
    </el-form-item>

    <!--<el-form-item label="银行">-->
    <!--<el-input v-model="userInfo.notifyBalance"></el-input>-->
    <!--</el-form-item>-->
    <el-form-item label="卡号">
      <el-input v-model="userInfo.cardNo"></el-input>
    </el-form-item>
    <el-form-item label="手机号">
      <el-input v-model="userInfo.cardPhone"></el-input>
    </el-form-item>
    <el-form-item label="持卡人">
      <el-input v-model="userInfo.cardPerson"></el-input>
    </el-form-item>

    <el-form-item label="自动提现金额">
      <el-input v-model="userInfo.autoCashBalance" auto-complete="off"></el-input>
    </el-form-item>
    <el-form-item label="备注">
      <el-input v-model="userInfo.remark" auto-complete="off"></el-input>
    </el-form-item>
    <el-form-item>
      <el-button type="warning" @click="generetorRSA">生成秘钥对</el-button>
      <el-button type="info" @click="quxiao">取消</el-button>
      <el-button type="primary" @click="revise">确定</el-button>
    </el-form-item>
  </el-form>
</template>

<script>
  import md5 from 'md5'

  export default {
    props: {
      userInfo: {
        type: Object
      }
    },
    data () {
      return {
        radio: 1
      }
    },
    methods: {
      generetorRSA(){
        this.$api.getUserKet().then(res => {
          if (res.code ==='000000'){
            this.userInfo.secretKey = res.data.RSAPrivateKey.encoded
            this.userInfo.publicKey = res.data.RSAPublicKey.encoded
            this.$message.success("生成RSA秘钥对成功！")
          }
        })
      },
      revise() {
        let _this = this;
        let params = {
          id: this.userInfo.id,
          secretKey: this.userInfo.secretKey,
          password: this.userInfo.password,
          cardNo: this.userInfo.cardNo,
          cardPerson: this.userInfo.cardPerson,
          cardPhone: this.userInfo.cardPhone,
          autoCashBalance: this.userInfo.autoCashBalance,
          remark: this.userInfo.remark,
          publicKey:this.userInfo.publicKey
        }
        if (params.password) {
          params.password = md5(params.password)
        } else {
          params.password = undefined
        }
        this.$api.reviseUser(params).then(function (res) {

          if (res.code == '000000') {
            console.log(res.data);
            _this.$emit("reviseUser", 'success');
          }
        })
      },
      quxiao() {
        this.$emit("reviseUser", 'error');
      }
    }
  }
</script>

<style>

</style>
